package com.zh.freechat.domain.message.repository.real;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zh.freechat.domain.message.entity.ChatGroupPO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author ZH
 * @date 23:21 2021/5/15
 */
@Mapper
public interface GroupPoMapper extends BaseMapper<ChatGroupPO> {
    /**
     * 查询群组数据，级联查询members
     *
     * @param groupNo
     * @return
     */
//    @Select("SELECT c FROM ChatGroupPO c JOIN FETCH c.users WHERE c.groupNo=:groupNo")
    ChatGroupPO findByGroupNo(@Param("groupNo") String groupNo);

    /**
     * 查询user的群组数据list，级联查询members
     *
     * @param userId
     * @return
     */
//    @Query("SELECT g FROM ChatGroupPO g JOIN FETCH g.users gm WHERE g.id IN (SELECT member.groupId FROM GroupMemberPO member WHERE member.userId = :userId)")
    List<ChatGroupPO> findGroupsByMember(@Param("userId") String userId);

    @Select(value = "select group_no from ch_group where id=#{groupId}")
    String getNoById(@Param("groupId") Long groupId);

    @Select(value = "select id from ch_group where group_no=#{groupNo}")
    Long getIdByNo(@Param("groupNo") String groupNo);

}
